package com.itheima.bos.service.system.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.bos.dao.system.PermissionRepository;
import com.itheima.bos.domain.system.Permission;
import com.itheima.bos.domain.system.User;
import com.itheima.bos.service.system.PermissService;

@Service
@Transactional
public class PermissServiceImpl implements PermissService {
	
	@Autowired
	private PermissionRepository permissionRepository;
	
	@Override
	public List<Permission> findByUser(User user) {
		if (user.getUsername().equals("admin")) {
			return permissionRepository.findAll();
		} else {
			return permissionRepository.findByUser(user.getId());
		}

	}
	
	@Override
	public List<Permission> findAll() {
		
		return permissionRepository.findAll();
	}
	
	@Override
	public void save(Permission model) {
		permissionRepository.save(model);	
	}

}
